﻿#pragma once

#include <QWidget>

#include "CefWebEngineCore/CefWebEnginePage.h"
#include "CefWebEngineWidgets/CefWebEngineWidgetsGlobal.h"

class CEFWEBENGINEWIDGETS_EXPORT CefWebEngineView : public QWidget
{
    Q_OBJECT

public:
    CefWebEngineView(QWidget *parent = nullptr);
    ~CefWebEngineView();

    void setPage(CefWebEnginePage *);
    CefWebEnginePage *page() const { return mpage; }
    CefWebEnginePage *setupEmptyPage(const QUrl &url);

    void load(const QUrl &url);

    void setFixedWindowTitleEnable(bool enable) { mfixWindowTitle = enable; }

signals:
    void loadStarted();
    void loadProgressChanged(int progress);
    void loadFinished(bool ok);
    void errorOccurred(const QString &error);

    void titleChanged(const QString &title);
    void urlChanged(const QUrl &url);
    void faviconUrlChanged(const QList<QUrl> &urls);
    void statusChanged(const QString &message);
    void toolTipChanged(const QString &message);
    void cursorChanged(const QCursor &cursor);

    void newWindowRequested(const QUrl &url, CefWebEnginePage **page);
    void resizeRequested(const QSize &size, bool &accept);
    void fullScreenRequested(bool fullScreen);
    void renderProcessTerminated();
    
protected:
    void resizeEvent(QResizeEvent *ev) override;

private:
    CefWebEnginePage *mpage;
    bool mfixWindowTitle;
};